package com.zzptc.mzb.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.zzptc.mzb.myapplication.entity.Qichepingbai;
import com.zzptc.mzb.myapplication.service.QichePinpaiService;

import java.lang.reflect.GenericSignatureFormatError;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getQichePinpaiInfo();
    }

    private void getQichePinpaiInfo() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://apis.juhe.cn/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        //创建接口对象
        QichePinpaiService qichePinpaiService=retrofit.create(QichePinpaiService.class);
        //调用接口对象中定义的方法
        Call<Qichepingbai> call=qichePinpaiService.getAllpinpai("e2a68c9e52b375c386286cf9747bf6d9","c");
        //调用Call接口中的异步方法
        call.enqueue(new Callback<Qichepingbai>() {
            @Override
            public void onResponse(Call<Qichepingbai> call, Response<Qichepingbai> response) {
                Qichepingbai qichepingbai=response.body();
                Log.d(TAG, "onResponse: "+qichepingbai.getResult().size());
            }

            @Override
            public void onFailure(Call<Qichepingbai> call, Throwable t) {
                Log.d(TAG, "onFailure: "+t.getMessage());
            }
        });

    }
}
